package com.liu.ai.embedding;

import org.springframework.ai.document.MetadataMode;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.openai.OpenAiEmbeddingOptions;
import org.springframework.ai.openai.api.OpenAiApi;

public class OpenAiEmbedding {

    private static final String apiKey = "sk-d1c41de66c074fc686488ab227d32fbe";


    public static void main(String[] args) throws InterruptedException {
        OpenAiApi openAiApi = OpenAiApi.builder()
                .apiKey(apiKey)
                .baseUrl("https://dashscope.aliyuncs.com")
                .completionsPath("/compatible-mode/v1/chat/completions")
                .embeddingsPath("/compatible-mode/v1/embeddings")
                .build();


        OpenAiEmbeddingOptions options = OpenAiEmbeddingOptions.builder()
                .model("text-embedding-v3")
                .dimensions(1024)
                .build();

        OpenAiEmbeddingModel openAiEmbeddingModel = new OpenAiEmbeddingModel(openAiApi, MetadataMode.EMBED,options);

        float[] embed = openAiEmbeddingModel.embed("风急天高猿啸哀");
        System.out.println(embed.length);
        Thread.sleep(60 * 1000);
    }
}
